package com.tanjun.userservice.web.convert;

import com.tanjun.userservice.apiservice.response.adminmenu.admin.AdminMenuRouteResponse;
import com.tanjun.userservice.web.service.menu.entity.BaseAdminMenuEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class AdminMenuConvert {

    public static AdminMenuRouteResponse convertToRoute(BaseAdminMenuEntity adminMenu){
        AdminMenuRouteResponse dto= AdminMenuRouteResponse.builder()
                .menuId(adminMenu.getMenuId())
                .name(adminMenu.getRouteName())
                .path(adminMenu.getRoutePath())
                .component(adminMenu.getComponent())
                .redirect(adminMenu.getRedirect())
                .meta(AdminMenuRouteResponse.Meta.builder()
                        .title(adminMenu.getMenuName())
                        .keepAlive(adminMenu.getKeepAlive())
                        .hidden(!adminMenu.getVisible())
                        .icon(adminMenu.getIcon())
                        .build()
                )
                .children(new ArrayList<>())
                .build();

        return dto;
    }

    public static List<AdminMenuRouteResponse> convertToRoutes(List<BaseAdminMenuEntity> list){
        return list.stream()
                .map(AdminMenuConvert::convertToRoute)
                .collect(Collectors.toList());
    }
}
